/*
 * UtfString.c
 *
 *  Created on: 2011-7-21
 *      Author: gexiao
 */

/*
 * UTF-8 and Unicode string manipulation, plus java/lang/String convenience
 * functions.
 *
 * In most cases we populate the fields in the String object directly,
 * rather than going through an instance field lookup.
 */
#include "Dalvik.h"
#include <stdlib.h>

/*
 * Compute a hash code on a UTF-8 string, for use with internal hash tables.
 *
 * This may or may not yield the same results as the java/lang/String
 * computeHashCode() function. (To make sure this doesn't get abused,
 * I'm initializing the hash code to 1 so they *don't* match up.)
 *
 * It would be more correct to invoke dexGetUtf16FromUtf8() here and compute
 * the hash with the result. That way, if something encoded the same
 * character in two different ways, the hash value would be the same. For
 * our purposes that isn't necessary.
 */
u4 dvmComputeUtf8Hash(const char* utf8Str) {
	u4 hash = 1;

	while (*utf8Str != '\0')
		hash = hash * 31 + *utf8Str++;

	return hash;
}

/*
 *
 */
StringObject* dvmCreateStringFromCstr(const char* utf8Str) {

}

/*
 *
 */
char* dvmCreateCstrFromString(StringObject* jstr) {

}
